package com.hzz.framework.config;

import com.hzz.framework.security.cipher.SM4Utils;
import com.hzz.framework.util.ValidatorUtil;
import lombok.Getter;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.annotation.Order;

@Configuration
@Slf4j
@Order(-998)
public class EncryptConfig {
    @Getter
    @Value("${data.security.prikey:A1B2C3D4E5F60708}")
    private String PRIKEY;
    @Getter
    @Value("${data.security.iv:C1D2H3X4B5D6WU1G}")
    private String IV;

    @Bean
    public SM4Utils getSm4Utils() {
        if (ValidatorUtil.isEmpty(getPRIKEY())) {
            throw new RuntimeException("SM4 SK不能为空");
        }
        if (ValidatorUtil.isEmpty(getIV())) {
            throw new RuntimeException("SM4 IV不能为空");
        }
        return new SM4Utils() {{
            setSecretKey(getPRIKEY());
            setIv(getIV());
        }};
    }
}
